<template>
  <van-row class="page-assess-dept-list">
    <van-nav-bar
      left-text="返回"
      right-text="确定"
      title="考核单位"
      @click-left="$emit('onCancel')"
      @click-right="doConfirm"/>
    <van-radio-group v-model="selectedDept">
      <van-cell-group>
        <card-assess-dept
          v-for="(depart) in departments"
          :key="depart.department_path"
          :department="depart"
          @onClick="selectedDept = depart"/>
      </van-cell-group>
    </van-radio-group>
    <van-empty v-if="departments.length < 1" description="无考核部门信息" />
    <loading-overlay :show="isLoading"/>
  </van-row>
</template>

<script>
import { getCheckDeptList } from '@/api/assess'
import CardAssessDept from '@/views/common/card/CardAssessDept'
export default {
  name: 'PageAssessDeptList',
  components: { CardAssessDept },
  props: ['assessType', 'depart'],
  data () {
    return {
      isLoading: false,
      departments: [],
      selectedDept: this.$vo.createDepartment()
    }
  },
  mounted () {
    this.doGetCheckDeptList()
  },
  methods: {
    doConfirm () {
      if (this.selectedDept.id === 0) {
        this.$dialog.alert({
          message: '请选择考核部门'
        })
        return
      }
      this.$emit('onConfirm', this.selectedDept.department_path)
    },
    doGetCheckDeptList () {
      this.isLoading = true
      getCheckDeptList(this.assessType, this.depart).then(res => {
        this.isLoading = false
        let { data } = res
        if (data[this.$response.CODE] === this.$response.SUCCESS) {
          this.departments = data['retData']
        } else {
          this.$toast.fail('获取数据失败：' + data[this.$response.MESSAGE])
        }
      }, errFunc => {
        this.isLoading = false
        this.$notify('服务调用失败：' + errFunc.toString())
        console.log(errFunc.toString())
      })
    }
  }
}
</script>

<style scoped lang="less">
  .page-assess-dept-list{
  }
</style>
